package com.xymtop.api.controller;

import com.xymtop.api.config.ServerStatus;
import com.xymtop.api.entity.MyApplication;
import com.xymtop.api.service.AppService;
import com.xymtop.api.utils.JsonResoult;
import com.xymtop.api.utils.Timer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName : AppController
 * @Description : 申请控制
 * @Author : 肖叶茂
 * @Date: 2022/12/1  19:16
 */
@RestController
@RequestMapping("app")
public class AppController {

    @Autowired
    private  AppService appService;

    @RequestMapping("add")
    public JsonResoult<String> add(String appuserid,String projectid,String content,String type) {
        MyApplication app = new MyApplication();
        app.setAppuserid(appuserid);
        app.setContent(content);
        app.setProjectid(projectid);
        app.setType(type);
        app.setId(Timer.getTimeStamp().toString());
        app.setTime(Timer.getSmapleTime(Timer.getTimeStamp()));
        app.setStatus("1");
        if(appService.add(app)==0){
            return new JsonResoult<>(ServerStatus.Fail);
        }else {
            return new JsonResoult<>(ServerStatus.SUCCESS);
        }

    }


    @RequestMapping("changeStatus")
    public JsonResoult<String> changeStatus(String id, String type) {
        if(appService.changeStatus(id,type)==0){
            return new JsonResoult<>(ServerStatus.Fail);
        }else {
            return new JsonResoult<>(ServerStatus.SUCCESS);
        }
    }


    @RequestMapping("getListUser")
    public List<MyApplication> getListUser(String userid) {
        return appService.getListUser(userid);
    }


    @RequestMapping("getListPro")
    public List<MyApplication> getListProject(String projectid) {
        return appService.getListProject(projectid);
    }
}
